package com.ln.lnzw.adapter;

import android.support.annotation.Nullable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ln.lnzw.R;
import com.ln.lnzw.bean.ServiceSubscribeServiceBean;

import java.util.List;

/**
 * 作者 : wlt
 * 创建时间:  2018-04-24
 * QQ : 1346947404
 * 邮箱:wanglt_android@163.com
 * 类说明:
 * In me the tiger sniffs the rose
 */

public class ServiceSubscribeServiceAdapter extends BaseMultiItemQuickAdapter<ServiceSubscribeServiceBean,BaseViewHolder> {

   private  RelativeLayout rl_subscribe_content;
   private  ImageView icon;

   private RelativeLayout rl_subscribe_add;


    public ServiceSubscribeServiceAdapter(@Nullable List<ServiceSubscribeServiceBean> data) {
        super( data);
        addItemType(ServiceSubscribeServiceBean.TYPE_NORMAL,R.layout.item_fuwu_subscribe_item);
        addItemType(ServiceSubscribeServiceBean.TYPE_ADD,R.layout.item_fuwu_subscribe_add);
    }

    @Override
    protected void convert(BaseViewHolder helper, ServiceSubscribeServiceBean item) {

        switch (item.getItemType()){

            case ServiceSubscribeServiceBean.TYPE_NORMAL:
                rl_subscribe_content = helper.getView(R.id.rl_subscribe_content);

                ViewGroup.LayoutParams layoutParams =rl_subscribe_content.getLayoutParams();
                layoutParams.width = ((ScreenUtils.getScreenWidth()-100)*32)/100; //宽度为去掉间隔之后还剩下3.2个view的宽度
                layoutParams.height = layoutParams.width*9/16; //宽高比是16/9
                rl_subscribe_content.setLayoutParams(layoutParams);

                icon = helper.getView(R.id.iv_service_subscribe_icon);

                ViewGroup.LayoutParams layoutParams1 = icon.getLayoutParams();
                layoutParams1.width = ScreenUtils.getScreenWidth()*7/110;
                layoutParams1.height = ScreenUtils.getScreenWidth()*7/110;
                icon.setLayoutParams(layoutParams1);

                helper.setText(R.id.tv_service_subscribe_name,item.getAppName());
                Glide.with(mContext).load(item.getAppIcon()).placeholder(R.mipmap.icon_fwzwt03).error(R.mipmap.icon_fwzwt03).into(icon);

                if (item.isSeclected()){
                    helper.setGone(R.id.iv_subscribe_delete,true);
                }else {
                    helper.setGone(R.id.iv_subscribe_delete,false);
                }
                helper.addOnClickListener(R.id.iv_subscribe_delete)//删除按钮增加点击事件
                       .addOnClickListener(R.id.rl_subscribe_content)//整体增加点击事件
                       .addOnLongClickListener(R.id.rl_subscribe_content);//整体增加长按事件
                break;
            case ServiceSubscribeServiceBean.TYPE_ADD:

                rl_subscribe_add = helper.getView(R.id.rl_subscribe_add);

                ViewGroup.LayoutParams layoutParamsAdd =rl_subscribe_add.getLayoutParams();
                layoutParamsAdd.width = ((ScreenUtils.getScreenWidth()-100)*32)/100; //宽度为去掉间隔之后还剩下3.2个view的宽度
                layoutParamsAdd.height = layoutParamsAdd.width*9/16; //宽高比是16/9

                rl_subscribe_add.setLayoutParams(layoutParamsAdd);
                helper.addOnClickListener(R.id.rl_subscribe_add);//增加增加按钮的点击事件
                break;
        }


    }
}
